#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os
import redis
from mq.rds_queue import RdsQueue
from basic.stat import RdsStat
from basic.proxy import SquidProxy
from basic.mdb import DbMysql


def get_rds():
    redis_host = os.getenv('REDIS_HOST', '127.0.0.1')
    redis_port = int(os.getenv('REDIS_PORT', '6379'))
    redis_password = os.getenv('REDIS_PASSWORD', '')
    return redis.Redis(host=redis_host, port=redis_port, db=0, password=redis_password, decode_responses=True)


def get_mq(rds):
    return RdsQueue(rds)


def get_stat(rds):
    return RdsStat(rds)


def get_squid_proxy():
    # 代理
    squid_host = os.getenv('SQUID_HOST', '10.0.1.31')
    squid_port = int(os.getenv('SQUID_PORT', '8888'))
    return SquidProxy(squid_host, squid_port)


# def get_mdb():
#     # 数据库连接
#     mysql_host = os.getenv('MYSQL_HOST', '120.25.148.180')
#     mysql_port = int(os.getenv('MYSQL_PORT', '21636'))
#     mysql_user = os.getenv('MYSQL_USER', 'spider6')
#     mysql_password = os.getenv('MYSQL_PASSWORD', 'Lingniao@Spider666')
#     mysql_db = os.getenv('MYSQL_DB', 'spider')
#     mdb = DbMysql(mysql_host, mysql_port, mysql_user, mysql_password, mysql_db)
#     mdb.connect()
#     return mdb

def get_mdb():
    # 数据库连接
    mysql_host = os.getenv('MYSQL_HOST', '127.0.0.1')
    mysql_port = int(os.getenv('MYSQL_PORT', '3306'))
    mysql_user = os.getenv('MYSQL_USER', 'root')
    mysql_password = os.getenv('MYSQL_PASSWORD', 'root')
    mysql_db = os.getenv('MYSQL_DB', 'test')
    mdb = DbMysql(mysql_host, mysql_port, mysql_user, mysql_password, mysql_db)
    mdb.connect()
    return mdb
